package com.sqx.modules.trendsComment.controller;

import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.trendsComment.entity.TrendsComment;
import com.sqx.modules.trendsComment.service.ITrendsCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 动态评论-用户端
 *
 * @author wuChang
 * @since 2023-09-26
 */
@RestController
@Api(value = "动态评论-用户端", tags = {"动态评论-用户端"})
@RequestMapping("/app/trendsComment/")
public class AppTrendsCommentController {
    @Autowired
    private ITrendsCommentService iTrendsCommentService;

    /**
     * 新增动态评论
     *
     * @param trendsComment
     * @return
     */
    @Login
    @ApiOperation("新增或修改动态评论")
    @PostMapping(value = "saveTrendsComment")
    public Result saveTrendsComment(@ApiParam("用户id")@RequestAttribute("userId") Long userId,
                                    @ApiParam("动态评论实体")TrendsComment trendsComment) {
        trendsComment.setUserId(userId);
        trendsComment.setIsLook(0);
        return iTrendsCommentService.saveTrendsComment(trendsComment);
    }
    /**
     * 获取评论列表
     *
     * @param page          第几页
     * @param limit         多少条
     * @param trendsComment
     * @return
     */
    @ApiOperation("获取评论列表")
    @GetMapping(value = "getCommentList")
    public Result getCommentList(@ApiParam("页码")Integer page,
                                 @ApiParam("条数")Integer limit,
                                 @ApiParam("被查看用户id")Long byUserId,
                                 @ApiParam("动态评论实体")TrendsComment trendsComment) {
        return Result.success().put("data", iTrendsCommentService.getAppCommentList(page, limit,byUserId, trendsComment));
    }

    /**
     * 获取未查看的评论列表
     *
     * @param page          第几页
     * @param limit         多少条
     * @return
     */
    @Login
    @ApiOperation("获取未查看的评论列表")
    @GetMapping(value = "getUnreadCommentList")
    public Result getUnreadCommentList(@ApiParam("页码")Integer page,
                                       @ApiParam("条数")Integer limit,
                                       @ApiParam("用户id")@RequestAttribute("userId") Long userId) {
        return Result.success().put("data", iTrendsCommentService.getUnreadCommentList(page, limit,userId));
    }

    /**
     * 删除评论
     *
     * @param commentId 评论id
     * @return
     */
    @Login
    @ApiOperation("删除评论")
    @PostMapping(value = "deleteTrendsComment")
    public Result deleteTrendsComment(@ApiParam("评论id")Long commentId,@RequestAttribute Long userId) {
        return iTrendsCommentService.deleteCommentById(commentId,userId);
    }

    @Login
    @ApiOperation("回复动态评论")
    @PostMapping(value = "replyTrendsComment")
    public Result replyTrendsComment(@ApiParam("用户id")@RequestAttribute("userId") Long userId,
                                     @ApiParam("动态评论实体")TrendsComment trendsComment) {
        trendsComment.setUserId(userId);
        return iTrendsCommentService.replyTrendsComment(trendsComment);
    }
}
